#ifndef UDPCOM_H
#define UDPCOM_H

#include "icom.h"
#include <QUdpSocket>
#include <QSemaphore>
#include <QThread>

class UdpCom : public ICom
{
    Q_OBJECT
public:
    UdpCom();

	bool IsConnected() override;

	bool Connect(char *port, char *args) override;
	bool Disconnect() override;

	int  GetChar(int timeout) override;
	void PutChar(char c) override;

	int  GetPacket(ComMessage &message, int timeout = -1) override;
	void PutPacket(ComMessage &message) override;

private:
    const QString m_cDefaultAddress = "0.0.0.0";
    const QString m_cDefaultPort = "62301";

    QString m_address;
    QString m_port;

    QUdpSocket *m_socket;
    QSemaphore *m_sem;
    ComMessage m_message;

	QThread *m_thread;
	bool m_thread_running;

public slots:
    void Udp_ReadyRead();

};

#endif // UDPCOM_H
